﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MyLibary.DAL;

namespace MyLibary.BIZ
{
    public class BIZ_HoaDonBan
    {
        #region Fields
        public  string MaHDBan { get; set; }
        public DateTime NgayLap { get; set; }
        public string MaKhachHang { get; set; }
        public decimal TongTien { get; set; }
        public int TrangThai { get; set; }
        public BIZ_NguoiDung KhachHang { get { return DAL_NguoiDung.GetUser(this.MaKhachHang); } }
        #endregion
        #region Constructor
        public BIZ_HoaDonBan(){}
        public BIZ_HoaDonBan(string MaHDBan, DateTime NgayLap, string MaKhachHang, int TrangThai,decimal TongTien)
        {
            this.MaHDBan = MaHDBan;
            this.NgayLap = NgayLap;
            this.MaKhachHang = MaKhachHang;
            this.TrangThai = TrangThai;
            this.TongTien = TongTien;
        }
        #endregion
        #region Metholds
        /// <summary>
        /// lấy danh sách hóa đơn bán
        /// </summary>
        /// <returns></returns>
        public static List<BIZ_HoaDonBan> GetAll()
        {
            return DAL_HoaDonBan.GetAll();
        }
        public static BIZ_HoaDonBan getByID(string MaHDBan)
        {
            return DAL_HoaDonBan.GetHoaDonBan(MaHDBan);
        }
        /// <summary>
        /// kiểm tra 1 hóa đơn bán có tồn tại hay chưa
        /// </summary>
        /// <returns></returns>
        public bool isExists()
        {
            return DAL_HoaDonBan.GetHoaDonBan(this.MaHDBan) != null;
        }
        /// <summary>
        /// thêm mới 1 chi tiết hóa đơn
        /// </summary>
        /// <returns></returns>
        public bool Add()
        {
            return DAL_HoaDonBan.Insert(this);
        }
        /// <summary>
        /// xóa 1  hóa đơn bán
        /// </summary>
        /// <returns></returns>
        public bool Delete()
        {
            return DAL_HoaDonBan.Delete(this);
        }
        //cập 1 hóa đơn bán
        public bool Update()
        {
            return DAL_HoaDonBan.Update(this);
        }
        #endregion
    }
    public class IEQualityCompareHoaDonBan : IEqualityComparer<BIZ_HoaDonBan>
    {
        #region IEQualityCompareHoaDonBan
        public bool Equals(BIZ_HoaDonBan x, BIZ_HoaDonBan y) { return x.MaHDBan == y.MaHDBan; }
        public int GetHashCode(BIZ_HoaDonBan HDBan) { return HDBan.GetHashCode(); }
       #endregion

    }
}
